13. CODE: Create a Comparison Function

Create a Comparison Function

L2 Create A Comparison Function

Before you can use the vector of open nodes to expand the A* search, you will first need to be able to sort the vector. Since the vector contains nodes {x, y, g, h}, and there is no standard library function to sort these types of vectors, you will begin by writing a function which compares two nodes to determine their order.

This function is a helper function for the CellSort() function you will write later, so it is not shown on the code structure diagram.

To Complete This Exercise:

Write a function bool Compare that accepts two nodes of type vector<int> as arguments. It should return a boolean true if the f-value of the first argument is greater than the f-value of the second, and it should return false otherwise. Recall that the f-value is the sum of the cost and heuristic: f = g + h.

Workspace

This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity, so you may be able to download them there.

Workspace Information:

  • Default file path:
  • Workspace type: generic
  • Opened files (when workspace is loaded): n/a
  • userCode:

    export CXX=g++-7
    export CXXFLAGS=-std=c++17
    g++() {
    /usr/bin/g++-7 -std=c++17 "$1"
    }
    export -f g++